'''
print("input函数的工作原理")
message=input("tell me something,and i will repeat it back to you: ")
print(message)


print("\n编写清晰的提示")
name=input("please enter your name: ")
print(f"hello,{name.title()}")


print('\n有时候提示可能超过一行，可以将提示赋给一个变量，再将变量传递给input()函数')
prompt="if you share your name,we can personalise the messages you see."
prompt+="\nwhat is your first name? "
name=input(prompt)
print(name)


print("\n使用int()来获取数值输入")
print("一、在使用input时。python会将用户输入的解读为字符串，")
age=input("how old are you? ")
print(age)
print(type(age))
print(age >= 18)

print("可使用函数int()将输入的字符串转换为数值")
age=input("how old are you? ")
age=int(age)
print(age)
print(type(age))
print(age >= 18)



print("在实际程序中使用int()函数，判断一个人是否满足坐过山车的身高要求")
height=input("how tall are you,in inches? ")
height=int(height)
if height>=48:
    print("you are tall enough to ride!")
else:
    print("you'll be able to ride when you're a little older.")


print("求模运算符%，将两个数相除并返回余数")
print(4%3)
print(5%3)
print(6%3)
print(7%3)
print("判断一个数是奇数还是偶数")
number=int(input("enter a number,and i'll tell you if it's even or odd: "))
if number%2==0:
    print(f"the number {number} is even.")
else:
    print(f"the number {number} is odd.")



print("练习7.1：汽车租赁")
car=input("what kind of car do you want to rent? ")
print(f"let me see if i can find you a {car.title()}")
print("练习7.2：餐馆定位")
people_number=int(input("how many people are coming to the dinner party? "))
if people_number >=8:
    print("sorry,there are no empty tables available.")
else:
    print("there are available tables.")
print("练习7.3:10的整数倍")
number="enter a number,and i'll tell you if it's multiple of 10."
number+="what's the number? "
number=int(input(number))
if number%10==0:
    print(f"the number {number} is multiple of 10.")
else:
    print(f"the number {number} is not multiple of 10.")



print("for循环针对集合中的每个元素执行一个代码块，while循环则不断地运行，直到指定条件不满足为止")
print("使用while循环数数，从1数到6")
current_number=1
while current_number <= 6:
    print(current_number)
    current_number+=1

current_number=1
while current_number <= 6:
    print(current_number,end="  ")
    current_number+=1



print("让用户选择何时退出，可以在其中设置一个退出值，只要用户输入的不是这个值，程序就一直运行")
prompt="tell me something,and i'll repeat it back to you:"
prompt+="\nenter 'quit' to end the program. "
message=""
while message!='quit':
    message=input(prompt)
    print(message)
print("美中不足的是，将quit也打印出来了，解决这种问题，只需要使用一个简单的if测试")
prompt="tell me something,and i'll repeat it back to you:"
prompt+="\nenter 'quit' to end the program. "
message=""
while message!='quit':
    message=input(prompt)
    if message!='quit':
        print(message)


print("使用标志，在要求满足很多条件才继续运行的程序中，可定义一个变量，用于判断整个程序是否处于活动状态，这个变量成为标志")
print("设置一个标志：active,用于判断程序是否继续运行")
prompt="tell me something,and i'll repeat it back to you:"
prompt+="\nenter 'quit' to end the program. "
active=True
while active:
    message=input(prompt)
    if message=='quit':
        active=False
    else:
        print(message)



print("使用breakf退出循环，")
prompt="please enter the name of a city you have visited:"
prompt+="\nenter 'quit' when you are finished. "
while True:
    city=input(prompt)
    if city=='quit':
        break
    else:
        print(city)

print("在所有python循环中都可以使用break语句")
cities=['chengdu','suining','zigong','mianyang']
for i in cities:
    if i=='zigong':
        break
    else:
        print(i)

cities=['chengdu','suining','zigong','mianyang']
for i in cities:
    if i=='zigong':
        break
    print(i)
    #??????

cities=['chengdu','suining','zigong','mianyang']
for i in cities:
    if i=='zigong':
        break
        print(i)        #?????
    else:
        print(i)


print("在循环中使用continue，要返回循环开头，并根据条件测试的结果决定是否继续执行循环，可使用continue语句")
print("只打印其中奇数的循环")
current_number = 0
while current_number <10:
    current_number+=1
    if current_number % 2 == 0:
        continue
    print(current_number)


print("避免无限循环")
x=1
while x<5:
    print(x)
    x+=1
print("若忘了x+=1,则进入了无限循环，可按ctrl+c，也可关闭显示程序输出的终端窗口")
x=1
while x<5:
    print(x)


print("练习7.4：比萨配料")
topping="please enter the pizza toppings you need"
topping+="\nif you finished,please enter 'quit'. "
active=True
while active:
    toppings=input(topping)
    if toppings=='quit':
        active=False
    else:
        print(f"you need {toppings}")

print("练习7.5：电影票")
age="please tell me your age,and i'll tell you the movie ticket price"
age+="\nenter your age: "
while True:
    ages = input(age)
    if int(ages)<3:
        print("the ticket price is free.")
    elif int(ages)<12:
        print("the ticket price is $10")
    elif int(ages)>=12:
        print("the ticket price is $15")
    else:
        print(ages)

print("练习7.6：三种出路")
age="please tell me your age,and i'll tell you the movie ticket price"
age+="\nenter your age: "
while True:
    ages = input(age)
    if ages=='quit':
        break
    elif int(ages)<3:
        print("the ticket price is free.")
    elif int(ages)<12:
        print("the ticket price is $10")
    elif int(ages)>=12:
        print("the ticket price is $15")
    else:
        print(ages)


age="please tell me your age,and i'll tell you the movie ticket price"
age+="\nenter your age: "
active=True
while active:
    ages = input(age)
    if ages=='quit':
        active=False
    elif int(ages)<3:
        print("the ticket price is free.")
    elif int(ages)<12:
        print("the ticket price is $10")
    elif int(ages)>=12:
        print("the ticket price is $15")
    else:
        print(ages)

age="please tell me your age,and i'll tell you the movie ticket price"
age+="\nenter your age: "
ages=""
while ages!="quit":
    ages = input(age)
    if ages=="quit":
        print('')
    elif int(ages)<3:
        print("the ticket price is free.")       #?????
    elif int(ages)<12:
        print("the ticket price is $10")
    elif int(ages)>=12:
        print("the ticket price is $15")

print("练习7.7：无限循环")
a=3
while True:
    print(a)

a=3
while a<6:
    print(a)
 
'''
print("使用while循环处理列表和字典")
print("for循环是一种遍历列表的有效方式，但不应该在for循环中修改列表，要在遍历列表的同时修改它，使用while循环")
print("在列表之间移动元素")
print("假设有一个列表包含新注册但还未验证的网站用户，验证这些用户后，如何将他们移到已验证的列表中，可使用while")
unconfirmed_users=['alice','brian','candace']
confirmed_users=[]
while unconfirmed_users:
    current_user=unconfirmed_users.pop()
    print(f"verifying user:{current_user}")
    confirmed_users.append(current_user)
print("the following users have been confirmed:")
for confirmed_user in confirmed_users:
    print(confirmed_user)

print("\n删除为特定值的所有列表元素")
print("使用remove()方法删除列表中的特定值，假设一个宠物列表，其中包含多个值为'cat'的元素，可以不断运行while循环")
pets=['dog','cat','dog','goldfish','cat','tabbit','cat']
print(pets)
while 'cat'in pets:
    pets.remove('cat')
print(pets)


print("\n使用用户输入填充字典")
print("可以使用while循环提示用户输入任意多的信息")
responses={}
polling_active=True
while polling_active:
    name=input("\nwhat is your name? ")
    response=input("which mountain would you like to climb someday? ")
    responses[name]=response
    repeat=input("would you like to let another person respond?(yes/no)")
    if repeat=="no":
        polling_active=False
print("---poll results---")
for name,response in responses.items():
    print(f"{name} would like to climb {response}")

print("练习7.8：熟食店")
sandwich_orders=['chicken sandwich','tuna sandwich','black forest ham','poast beef']
finished_sandwiches=[]
while sandwich_orders:
    sandwich_order=sandwich_orders.pop()
    print(f"i made your {sandwich_order}.")
    finished_sandwiches.append(sandwich_order)
print("the finished sandwiches are:")
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich)


print("\n练习7.9：五香烟熏牛肉卖完了")
sandwich_orders=['chicken sandwich','pastrami','tuna sandwich',
                 'pastrami','black forest ham','poast beef','pastrami']
finished_sandwiches=[]
print("pastrami sandwich is sold out.")
while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')
while sandwich_orders:
    sandwich_order=sandwich_orders.pop()
    print(f"i made your {sandwich_order}.")
    finished_sandwiches.append(sandwich_order)
print("the finished sandwiches are:")
for finished_sandwich in finished_sandwiches:
    print(finished_sandwich)



print("\n练习7.10：梦想中的度假胜地")
names="please enter your name: "
places="if you could visit one place in the world,where would you go? "
info_places= {}
while True:
    name=input(names)
    place=input(places)
    info_places[name]=place
    ask=input("let anthoner people response?(yes/no) ")
    if ask=="no":
        break
for a,b in info_places.items():
    print(f"{a}'d like to {b}")

